import java.util.*;

class CalendarSeeker {
    private static final int GIVEN_YEAR = 2000;
    private static final int GIVEN_MONTH = 12;
    private static final int LEAP_YEARS_COEFFICIENT = 4; // each 4th year is a leap year
    private static final int DAYS_NUMBER_IN_YEAR = 365;
    private static final int DAYS_NUMBER_IN_WEEK = 7;
        
    private Date date;

    public CalendarSeeker(Date date) {
        this.date = date;
    }
	
	public DayOfWeek getDayOfWeek() {
        int yearDifferenceInDays = computeYearDifferenceWithLeapDays();
        int monthDifference = computeMonthDifference();
        int overallDifference = computeOverallDifference(yearDifferenceInDays, monthDifference);
        return DayOfWeek.values()[computeWeekDayNumber(overallDifference)];
    }
    
    private int computeYearDifferenceWithLeapDays() {
        int yearDifferenceInYears = date.getYear() - GIVEN_YEAR; 
        int leapDays = (int) Math.floor(yearDifferenceInYears / (float)LEAP_YEARS_COEFFICIENT); // round down to the nearest int
        int yearDifferenceInDays = yearDifferenceInYears * DAYS_NUMBER_IN_YEAR; 
        yearDifferenceInDays += leapDays;
        return yearDifferenceInDays;
    }
	
	private int computeMonthDifference() {
		int result = 0;
        Months[] months = Months.values();
        for (int i = GIVEN_MONTH - 1; i >= date.getMonth() - 1; i--) {
            result += months[i].getDaysCount(); 
        }
		return result;
	}
    
    private int computeOverallDifference(int yearDifferenceInDays, int monthDifference) {
        final int FEBRUARY = 2;
        int result = Math.abs(yearDifferenceInDays - monthDifference + date.getDay());
        boolean inputDateIsGraterLessOrEqualToFebruary29 = (date.getYear() == GIVEN_YEAR) && (date.getMonth() <= FEBRUARY) && (date.getDay() <= 29);
        if (inputDateIsGraterLessOrEqualToFebruary29) { 
            result++;
        }
        return result;
    }
    
    private int computeWeekDayNumber(int overallDifference) {
        int result = overallDifference % DAYS_NUMBER_IN_WEEK; 
        if ((date.getYear() <= GIVEN_YEAR) && (result != 0)) {
            result = DAYS_NUMBER_IN_WEEK - result;
        }
        return result;
    }
}              